﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CastleDemo1.Model;
using Castle.ActiveRecord;
namespace CastleDemo1
{
    /// <summary>
    /// CheckExistHandler 的摘要说明
    /// </summary>
    public class CheckExistHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Request.Form["posttitle"] != null)
            {
                string title = context.Request.Form["posttitle"];
                bool exist = Exists("Title", title);
                if (exist)
                {
                    context.Response.Write("已经存在");
                }
                else
                {
                    context.Response.Write("可以使用");
                }
            }
            else
            {
                context.Response.Write("不存在");
            }                   
            
        }
        private bool Exists(string prop, string val)
        {
           Post[] posts=Post.FindAllByProperty(prop, val);
           if (posts!=null && posts.Length>0)
           {
               return true;
           }
           return false;
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}